<template>
   <div class="box">
       信息标题： <input type="text" v-model="writing[0]">
       <br>
       版权所有： <input type="text" v-model="writing[1]">
       <br>
       工作时间： <input type="text" v-model="writing[2]">
       <br>
       联系方式： <input type="text" v-model="writing[3]">
       <br>
       <button @click="writing_">保存</button>
   </div>
</template>

<script>
import api from "@/api";

export default {
    name: "SiteInformation",
    data(){
        return{
            writing:[],
        }
    },
    created() {
        let writing = JSON.parse(window.localStorage.getItem("DataContent"));
        setTimeout(()=>{
            if(writing){
                for(let i=0;writing.length;i++){
                    if(writing[i].options === "siteInformation_title"){
                        this.writing = writing[i].content.split("|||||");
                        return;
                    }
                }
            }
        },200)

    },
    methods:{
        writing_(){
            let writing = "";
            for(let i=0;i<this.writing.length;i++){
                if(i<this.writing.length-1){
                    writing+=this.writing[i]+"|||||";
                }else{
                    writing+=this.writing[i];
                }
            }
            api.updateAdminWeb({content:writing,options: "siteInformation_title"}).then((res)=>{
                this.$store.commit("requestInfo", res.data.msg);
                if(res.data.code===200){
                    api.getAdminWeb().then((res)=>{
                        window.localStorage.setItem("DataContent",JSON.stringify(res.data.data))
                    })
                }
            })
        }

    }
}
</script>

<style scoped>
.box{
    padding: 15px;
    background: white;
}
input{
    outline: none;
    height: 30px;
    width: 250px;
    margin-bottom: 15px;
}

button{
    padding: 7px 15px;
    outline: none;
    background: #3586f1;
    border: 0;
    border-radius: 3px;
    color: white;
    cursor: pointer;
    z-index: 9;
}
button:hover{
    opacity: .9;
}
</style>